import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:fucius/Models/talentModel.dart';
import 'package:fucius/Models/JobModel.dart';
import 'package:fucius/utils/DotsIndicator.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

import 'jobInfo.dart';

class JobDetail extends StatefulWidget {
  JobDetail(this._job);

  final JobModel _job;

  @override
  _JobDetailState createState() => _JobDetailState();
}

class _JobDetailState extends State<JobDetail> with TickerProviderStateMixin {
  List<Tab> _tabs;
  List<Widget> _imagePages;
  TabController _controller;
  List<String> _urls = [
    "https://www.nextpittsburgh.com/wp-content/uploads/2016/06/CMULarge-e1467683012612.jpg",
    "https://admission-writer.com/static/img/regular/cmu1.jpg",
    "https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQqU-V--bB9Qw-AceCxnG87kv3vrnF_AAa5PjICx1ESoveJvpI2"
  ];
  Widget _jobTabContent;
  VoidCallback onChanged;
  int _currentIndex = 0;


  @override
  void initState() {
    super.initState();
    if (_urls.isNotEmpty) {
      _imagePages = <Widget>[];
      _urls.forEach((String url) {
        _imagePages.add(Container(
            color: Colors.black.withAlpha(900),
            child: ConstrainedBox(
              constraints: BoxConstraints.expand(),
              child: Image.network(
                url,
                fit: BoxFit.cover,
                height: 256.0,
              ),
            )));
      });
    }

    _tabs = [
      new Tab(text: 'Description'),
      new Tab(text: 'Qualifications'),
    ];
    _jobTabContent = new JobInc(job: widget._job.topic);
    _controller = new TabController(length: _tabs.length, vsync: this);

    onChanged = () {
      setState(() {
        if (_currentIndex == 0) {
          _jobTabContent = JobInc(job: widget._job.topic);
        } else {
//TODO
        }
        _currentIndex = this._controller.index;
      });
    };
    _controller.addListener(onChanged);
  }

  @override
  void dispose() {
    _controller.removeListener(onChanged);
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: new Color.fromARGB(255, 242, 242, 245),
      body:Stack(
        children: <Widget>[
          SingleChildScrollView(
              child: new Column(
                children: <Widget>[
                  new SizedBox.fromSize(
                    size: const Size.fromHeight(256.0),
                    child: IndicatorViewPager(pages: _imagePages),
                  ),
                  new Container(
                    color: Colors.white,
                    child: new Column(
                      children: <Widget>[
                        new JobInfo(job: widget._job),
                        new Divider(),
                        new TabBar(
                          indicatorWeight: 3.0,
                          indicatorSize: TabBarIndicatorSize.tab,
                          labelStyle: new TextStyle(fontSize: 16.0),
                          labelColor: Colors.black,
                          controller: _controller,
                          tabs: _tabs,
                          indicatorColor: Theme.of(context).primaryColor,
                        ),
                      ],
                    ),
                  ),
                  _jobTabContent
                ],
              )),
        ],
      ),
    );
  }
}

class JobInc extends StatelessWidget {
  JobInc({this.job});

  final String job;

  @override
  Widget build(BuildContext context) {
    return Padding(
        padding: EdgeInsets.only(
          top: 10.0,
          left: 10.0,
          right: 10.0,
          bottom: 10.0,
        ),
        child: Container(
            color: Colors.white,
            child: Padding(
                padding: EdgeInsets.all(15.0),
                child: Column(
                  children: <Widget>[
                    Row(
                      children: <Widget>[
                        Container(
                          margin: const EdgeInsets.only(bottom: 10.0),
                          child: Text('Description', style: TextStyle(fontSize: 15.0)),
                        )
                      ],
                    ),
                    RichText(
                        text: TextSpan(
                      text: job,
                      style: TextStyle(fontSize: 14.0, color: Colors.black),
                    ))
                  ],
                ))));
  }
}
